package io.renren.controller;

import com.alibaba.fastjson.JSONObject;
import io.renren.entity.JobChangeManagementEntity;
import io.renren.entity.SysUserEntity;
import io.renren.service.JobChangeManagementService;
import io.renren.utils.PageUtils;
import io.renren.utils.QueryAuthority;
import io.renren.utils.R;
import io.renren.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 岗位异动管理
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-07-11 17:19:09
 */
@RestController
@RequestMapping("jobchangemanagement")
public class JobChangeManagementController extends AbstractController{
	@Autowired
	private JobChangeManagementService jobChangeManagementService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("jobchangemanagement:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        QueryAuthority query = new QueryAuthority(params);

		List<JobChangeManagementEntity> jobChangeManagementList = jobChangeManagementService.queryList(query);
		int total = jobChangeManagementService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(jobChangeManagementList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("jobchangemanagement:info")
	public R info(@PathVariable("id") Integer id){
		JobChangeManagementEntity jobChangeManagement = jobChangeManagementService.queryObject(id);
		
		return R.ok().put("jobChangeManagement", jobChangeManagement);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("jobchangemanagement:save")
	public R save(@RequestBody JobChangeManagementEntity jobChangeManagement){
		SysUserEntity entity= (SysUserEntity) ShiroUtils.getSubject().getSession().getAttribute("user");
		jobChangeManagement.setCdate(new Date());
		jobChangeManagement.setCusername(entity.getUsername());
		jobChangeManagement.setCreateCompanyId(entity.getCompanyId());
		jobChangeManagement.setCreateDeptId(entity.getDeptNo());

		jobChangeManagementService.save(jobChangeManagement);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("jobchangemanagement:update")
	public R update(@RequestBody JobChangeManagementEntity jobChangeManagement){
		jobChangeManagementService.update(jobChangeManagement);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("jobchangemanagement:delete")
	public R delete(@RequestBody Integer[] ids){
		jobChangeManagementService.deleteBatch(ids);
		
		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/approve")
	@RequiresPermissions("jobchangemanagement:delete")
	public R approve(@RequestBody  JSONObject params){
		jobChangeManagementService.approve(params);

		return R.ok();
	}
	
}
